odoo.define('web_tree_view_add_buttons', function (require) {
    "use strict";
var core = require('web.core');

var BasicController = require('web.BasicController');
var DataExport = require('web.DataExport');
var data = require('web.data');
var Dialog = require('web.Dialog');
var pyUtils = require('web.py_utils');
var Sidebar = require('web.Sidebar');

var ListRenderer = require('web.ListRenderer');

var _t = core._t;
var qweb = core.qweb;
var ListR=ListRenderer;
    var ListView = require('web.ListController');
    ListView.include({

    renderButtons: function ($node) {
		//this._super.apply(this, arguments);
        if (!this.noLeaf && this.hasButtons) {
			
            this.$buttons = $(qweb.render(this.buttons_template, {widget: this}));
            this.$buttons.on('click', '.o_list_button_add', this._onCreateRecord.bind(this));

            this._assignCreateKeyboardBehavior(this.$buttons.find('.o_list_button_add'));
            this.$buttons.find('.o_list_button_add').tooltip({
                delay: {show: 200, hide:0},
                title: function(){
                    return qweb.render('CreateButton.tooltip');
                },
                trigger: 'manual',
            });
            this.$buttons.on('click', '.o_list_button_discard', this._onDiscard.bind(this));
			
			//weishuai 2019-12-31
             var record = this.model.get(this.handle, {raw: true});
             var ctx =record.getContext();
		     var tree_buttons=ctx.buttons;			 

			
         
			var self = this;
            _.each(tree_buttons, function (button, index) {

             var $btn = $('<button>', {
                        "text": button.button_text,
                        "class": 'btn btn-primary  o_list_button_extra_1'+index ,
                        "type": 'button',
                        "title": button.button_text
            });
            if(button.tree_add=="ok")
		    {	
            console.log('-------ctx3:-------------');	 
            self.$buttons.append($btn);
			self.$buttons.append("&nbsp;");
			
            self.$buttons.on('click', '.o_list_button_extra_1'+index,self.do_fhworking_hours_record.bind(self, index));
		    }
			});
         

		   
		   //weishuai 2019-12-31
		  
           this.$buttons.appendTo($node);
        }
    },	
    do_fhworking_hours_record: function (index, event) {
			var self = this;		
            var record = this.model.get(this.handle, {raw: true});
            var ctx =record.getContext();
			var fhwizard=ctx.buttons[index].fhwizard;
			var fhaction=ctx.buttons[index].fhaction;
			///var fhwizard=ctx.buttons[index].fhwizard;			
            this.dataset = new data.DataSet(this,fhwizard,ctx);

            var SelectedIds =this.getSelectedIds();
            console.log('--------SelectedIds:--------------');				
            console.log(SelectedIds);			
			
			/*
			
            this.dataset._model.call(fhaction, [[],{'SelectedIds':SelectedIds},ctx]).done(function () {
			   self.update({});
            });
			*/
			

            self.do_action({
                name: "向导窗口",
                res_model: fhwizard,
                views: [[false, 'form']],
                type: 'ir.actions.act_window',
                target: "new",
                context: {'SelectedIds':SelectedIds},
                flags: {
                    action_buttons: true,
                }
            });			
			
        },	
	

    });

});
